var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    page:0,
    info:[],
    openid:'',
    myopenid:'',
    my:[],
    sendInput:'',
    page:1
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      openid:options.openid
    });
    var data = {};
    data.openid = options.openid;
    app.ihttpPost('https://www.58zltc.com/api.php/TakeOut/getUserInfo', data, function (res) {
      that.setData({
        info: res.data
      });
    })
    var myopenid = app.globalData.openid;
    that.setData({
      myopenid: myopenid
    });
    var mdata = {};
    mdata.openid = myopenid;
    app.ihttpPost('https://www.58zltc.com/api.php/TakeOut/getUserInfo', mdata, function (res) {
      that.setData({
        my: res.data
      });
    })
    var ldata = {};
    ldata.openid = that.data.openid;
    ldata.myopenid = that.data.myopenid;
    ldata.page = that.data.page;
    app.ihttpPost('https://www.58zltc.com/api.php/Quan/chatRecord', ldata, function (res) {
      that.setData({
        list: res.data
      });
    })
    app.ihttpPost('https://www.58zltc.com/api.php/Quan/setChatStatus', ldata, function (res) {

    })
    
  },
  sendInputBind:function(e){
    this.setData({
      sendInput: e.detail.value
    })
  },
  backto:function(e){
    wx.navigateBack({
    })
  },
  send: function (e) {
    var that = this;
    var data = {};
    data.openid = that.data.openid;
    data.myopenid = that.data.myopenid;
    data.text = that.data.sendInput;
    app.ihttpPost('https://www.58zltc.com/api.php/Quan/send', data, function (res) {
      that.setData({
        list: that.data.list.concat(res.data),
        sendInput:''
      });
      
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    let that = this;
    var newPage = that.data.page + 1;
    that.setData({
      page: newPage
    });
    console.log(that.data.page);
    var data = {};
    data.openid = that.data.openid;
    data.myopenid = that.data.myopenid;
    data.page = that.data.page;
    app.ihttpPost('https://www.58zltc.com/api.php/Quan/chatRecord', data, function (res) {
      wx.stopPullDownRefresh();
      that.setData({
        list: res.data
      });
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})